package utilities;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class JImage {
	public JImage(String origine, String destinazione) throws IOException {
		File fileImageOrig = new File(origine);
		File fileImageDest = new File(destinazione);
		BufferedImage originalImage = ImageIO.read(fileImageOrig);
		BufferedImage resizeImageJpg = resizeImage(originalImage,
				BufferedImage.TYPE_INT_RGB, 60, 100);
		ImageIO.write(resizeImageJpg, "jpg", fileImageDest);
	}

	private static BufferedImage resizeImage(BufferedImage originalImage,
			int type, int width, int height) {
		BufferedImage resizedImage = new BufferedImage(width, height, type);
		Graphics2D g = resizedImage.createGraphics();
		g.drawImage(originalImage, 0, 0, width, height, null);
		g.dispose();

		return resizedImage;
	}
}
